home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
276-300
/
283
/
bref
/
hsi.color
< prev
next >
Wrap
Text File
|
1995-03-14
|
2KB
|
140 lines
'Program HSI.Color
'HSI to RGB Conversion by Stephen Pietrowicz
'"Amazing Computing" Vol 1 #5 June 1986
' H = hue S = saturation I = intensity
SCREEN 1,640,200,4,2
WINDOW 2,"HSI to RGB",,0,1
DEF FNa(n) = 2*I*((S*n)+.5)
DEF FNb(n) = .5+(S*n)+2*(I-.5)*(.5-(S*n))
GOSUB Init
MouseInput:
GOSUB PrintVals
WHILE MOUSE(0) = 0: WEND
x = MOUSE(3): y = MOUSE(4)
IF (y<100) OR (y>180) THEN MouseInput
IF (x<50) OR (x>550) THEN MouseInput
'Hue selected
IF y<= 130 THEN
IF (x>=120) AND (x<=480) THEN
Hue = x-120
H = Hue/360
COLOR 0
LINE (hx,102)-(hx,128)
COLOR 1
LINE (x,102)-(x,128)
hx = x
END IF
'Saturation Selected
ELSEIF y >= 150 THEN
IF x <= 150 THEN
S = (x-50)/100
COLOR 0
LINE (sx,152)-(sx,178)
COLOR 1
LINE (x,152)-(x,178)
sx = x
'Intensity Selected
ELSEIF x >= 450 THEN
I = (x-450)/100
COLOR 0
LINE (ix,152)-(ix,178)
COLOR 1
LINE (x,152)-(x,178)
ix = x
END IF
END IF
GOSUB Convert
GOTO MouseInput
Init:
CLS
COLOR 3
LINE (118,100)-(482,130),,b
LINE (48,150)-(152,180),,b
LINE (448,150)-(552,180),,b
hx = 120: sx = 50: ix = 450
COLOR 1
LINE (hx,102)-(hx,128)
LINE (sx,152)-(sx,178)
LINE (ix,152)-(ix,178)
COLOR 2
LINE (50,25)-(550,75),,bf
COLOR 1
LINE (50,25)-(550,75),,b
r = 0: g = 0: b = 0: S = 0: I = 0
RETURN
'Change given HSI coords to RGB
Convert:
IF H < .16 THEN
Red = 1
Green = H*6
Blue = 0
ELSEIF H < .33 THEN
Red = 2-H*6
Green = 1
Blue = 0
ELSEIF H < .5 THEN
Red = 0
Green = 1
Blue = 6*H-2
ELSEIF H < .66 THEN
Red = 0
Green = 4-H*6
Blue = 1
ELSEIF H < .83 THEN
Red = H*6-4
Green = 0
Blue = 1
ELSE
Red = 1
Green = 0
Blue = 6-6*H
END IF
Red = Red-.5
Green = Green -.5
Blue = Blue-.5
IF I <= .5 THEN
Red = FNa(Red)
Green = FNa(Green)
Blue = FNa(Blue)
ELSE
Red = FNb(Red)
Green = FNb(Green)
Blue = FNb(Blue)
END IF
IF Red > 1 THEN Red = 1
IF Green > 1 THEN Green = 1
IF Blue > 1 THEN Blue = 1
IF Red < 0 THEN Red = 0
IF Green < 0 THEN Green = 0
IF Blue < 0 THEN Blue = 0
PALETTE 2,Red,Green,Blue
RETURN
PrintVals:
COLOR 3
LOCATE 2,22
PRINT USING "Red =#.##";Red;
PRINT USING "Green =#.##";Green;
PRINT USING "Blue =#.##";Blue
LOCATE 12,34
PRINT USING "Hue =###";Hue
LOCATE 18,5
PRINT USING "Saturation =#.##";S
LOCATE 18,55
PRINT USING "Intensity =#.##";I
COLOR 2
RETURN